{% extends "base.html" %}
{% block title %}{% endblock %}
{% block content %}
<br>

<form class="layui-form" action="" id="cross_srh" >
    <div class="proxy_srh" >
        <div class="layui-inline">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <label class="layui-form-label">项目*：</label>
                    <div class="layui-input-inline">
                        <select class="layui-select" name="project_name" id="project_name" lay-verify="" lay-search
                                lay-filter="project_name">
                            <option value="">请选择</option>
                            {% for d in projectAll %}
                            <option value="{{d.id}}">{{d.project_name}}</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
                <div class="layui-input-inline">
                    <label class="layui-form-label">任务状态：</label>
                    <div class="layui-input-inline">
                        <select class="layui-select" name="work_state" id="work_state" lay-verify="" lay-search
                                lay-filter="work_state">
                            <option value=''>请选择</option>
                            <option value='0'>打开</option>
                            <option value='1'>完成</option>
                            <option value='2'>暂停</option>
                            <option value='3'>废弃</option>
                        </select>
                    </div>
                </div>
                <div class="layui-input-inline">
                    <label class="layui-form-label">关键字：</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="key_words" id="key_words" placeholder="请输入"
                               style="width:212px">
                    </div>
                </div>
                <br><br>
                <div class="layui-input-inline">
                    <label class="layui-form-label">计划开始：</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="work_p_start" id="work_p_start" placeholder="请输入"
                               style="width:212px">
                    </div>
                </div>
                <div class="layui-input-inline">
                    <label class="layui-form-label">计划结束：</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="work_p_end" id="work_p_end" placeholder="请输入"
                               style="width:212px">
                    </div>
                </div>

                <div class="layui-inline" style="float:right;right: 2px">
                    <button class="layui-btn" type="button" id="start" lay-submit lay-filter="start">查询所有</button>
                </div>
            </div>
        </div>

    </div>
</form>
<hr class="layui-bg-gray">
<button class="layui-btn  layui-btn-normal" id="add" type="button">
    <i class="layui-icon"></i> 新建任务
</button>
<table class="layui-hide" id="casePlan" lay-filter="casePlan"></table>
<script type="text/html" id="filemange_v1">
    <button type="button" class="layui-btn layui-btn-xs " lay-event="process_add">进度</button>
    <button type="button" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="sub_task">子任务</button>
    <button type="button" class="layui-btn layui-btn-xs " lay-event="update">更新</button>
</script>
<script>
    layui.use(['table','element'], function(){
          var table = layui.table
          ,form = layui.form;
          var $= layui.jquery;
          var element = layui.element;
          var loading = layer.load();
          var  options = {
                elem:'#casePlan',
                skin:"line",
                page:true,
                height: 'full-200',
                toolbar: true,
                url:'/casePlan/main/srh?',
                limit:10,
                limits:[10,50,100],
                where:{
                    project_id : $('#project_name option:selected').val(),
                    work_state: $('#work_state option:selected').val(),
                    key_words: $('#key_words').val(),
                    work_p_start: $('#work_p_start').val(),
                    work_p_end: $('#work_p_end').val()
                },
                response:{
                    statusName:'errorCode',
                    statusCode:'',
                    dataName:'data'
                },
                cols:[[
                       {type: 'numbers',title:'No.'}
                      ,{field: 'project_id', title: '项目',sort:true, templet: function (d) {
                            return $("#project_name").find("option[value="+ d.project_id +"]").text();
                      }}
                      ,{field: 'plan_type', title: '阶段',sort:true, templet: function (d) {
                            if(d.plan_type == 0){
                                return '需求阶段';
                            } else if(d.plan_type == 1){
                                return '开发阶段';
                            }else if(d.plan_type == 2){
                                return '单元测试';
                            }else if(d.plan_type == 3){
                                return '集成测试';
                            }else if(d.plan_type == 4){
                                return '冒烟测试';
                            }else if(d.plan_type == 5){
                                return '系统测试';
                            }else if(d.plan_type == 6){
                                return '回归测试';
                            }else if(d.plan_type == 7){
                                return '验收测试';
                            }else if(d.plan_type == 8){
                                return '线上验证';
                            }else if(d.plan_type == 9){
                                return '总结阶段';
                            }

                       }}
                      ,{field: 'project_version', title: '版本',sort:true}
                      ,{field: 'work_state', title: '状态',sort:true, templet: function (d) {
                            if(d.work_state == 0){
                                return '<span style="color:red">打开</span>';
                            } else if(d.work_state == 1){
                                return '<span style="color:green">完成</span>';
                            } else if(d.work_state == 2){
                                return '暂停';
                            } else if(d.work_state == 3){
                                return '废弃';
                            }
                       }}
                      ,{field: 'work_p_start', title: '计划开始',sort:true}
                      ,{field: 'work_p_end', title: '计划结束',sort:true}
                      ,{field: 'work_end', title: '实际结束',sort:true}
                      ,{field: 'main_process', align:'center',title: '进度', templet: function (d) {
                          return '<div class="layui-progress layui-progress-big" lay-showPercent="yes">'+
                                '<div class="layui-progress-bar layui-bg-blue" lay-percent="'+d.main_process+'%"></div></div>';

                      }}
                      ,{field: 'work_charge', title: '责任人',sort:true, templet: function (d) {
                            return d.work_charge_name;
                      }}
                      ,{field: 'id', title: 'id',sort:true,hide:true}
                      ,{field: 'up_person', title: 'up_person',sort:true,hide:true,hide:true}
                      ,{field: 'update_time', title: 'update_time',sort:true,hide:true,hide:true}
                      ,{fixed: 'right', title:'', toolbar: '#filemange_v1',width:180}
                ]],
                id:'casePlan',
                done:function(res,cur,count){
                    element.render('main_process');
                    layui.each(res.data,function(index,item){
                         if(item.sub_task==""||item.sub_task==undefined){
                            }else{
                                $("tr[data-index='"+index+"']>td[data-field='0']").css('background','#efccd2');
                            }
                         if(item.work_state!="1"){
                             if(nowTime() > item.work_p_end ){
                                $("tr[data-index='"+index+"']>td[data-field='work_p_end']").css('color','red');
                             }
                         }


                    });

                    layer.close(loading);
                }
              };
          var tableIns = table.render(options);
          table.on('row(casePlan)', function(obj){
            obj.tr.css("background","greenyellow");
          });
          function nowTime(){
                var myDate = new Date;
                var year = myDate.getFullYear(); //获取当前年
                var mon = myDate.getMonth() + 1; //获取当前月
                if(mon<10){
                    mon = "0"+mon;
                }
                var date = myDate.getDate(); //获取当前日
                if(date<10){
                    date = "0"+date;
                }
                return year+"-"+mon+"-"+date;
          }
          //监听工具条
          table.on('tool(casePlan)', function(obj){
                if(obj.event ==='process_add'){

                    layui.data('test', {key: 'processList',value: {"id":obj.data.id,"t":0}});
                    layer.open({
                            type:2,
                            content:"/casePlan/main/process",
                            area:['1055px','493px'],
                            title:obj.data.project_version + "——进度",
                            closeBtn:1,
                            shade: 0,
                            shadeClose:true,
                            maxmin: true,
                            cancel: function(index, layero){
                                $('#start').click();
                            }
                     });

                }else if (obj.event ==='sub_task'){
                     //将项目、主任务id带到子任务中
                     layui.data('test', {key: 'CacheSubFromMain',value: {'c_end':obj.data.work_end,'p_end':obj.data.work_p_end,"project_id":obj.data.project_id,"id":obj.data.id}});

                     layer.open({
                                                type:2,
                                                content:"/casePlan/sub/index",
                                                area:['1000px','500px'],
                                                title:"子任务内容",
                                                closeBtn:1,
                                                shade: 0,
                                                shadeClose:true,
                                                maxmin: true,
                                                cancel: function(index, layero){
                                                    $('#start').click();
                                                }
                     });

                }else if (obj.event ==='update'){
                     if(obj.data.work_state==1){
                        layer.msg("已完成，不可更改!");
                        return false;
                     }
                     layui.data('test', {key: 'RowCasePlan',value: obj.data});
                     layer.open({
                                                type:2,
                                                content:"/casePlan/main/manage",
                                                area:['750px','410px'],
                                                title:"主任务管理",
                                                closeBtn:1,
                                                shade: 0,
                                                shadeClose:true,
                                                maxmin: true,
                                                cancel: function(index, layero){
                                                    $('#start').click();
                                                }
                     });
                }
          });

          //新增主任务 add
          $('#add').on('click',function(){
            layui.data('test', {key: 'RowCasePlan',value: undefined});
            layer.open({
                                                type:2,
                                                content:"/casePlan/main/manage",
                                                area:['750px','410px'],
                                                title:"主任务管理",
                                                closeBtn:1,
                                                shade: 0,
                                                shadeClose:true,
                                                maxmin: true,
                                                cancel: function(index, layero){
                                                    $('#start').click();
                                                }
            });

          });
          //点击查询
          $('#start').on('click',function(){
              var loading = layer.load();

              options = {
                elem:'#casePlan',
                skin:"line",
                page:true,
                height: 'full-200',
                toolbar: true,
                url:'/casePlan/main/srh?',
                limit:10,
                limits:[10,50,100],
                where:{
                    project_id : $('#project_name option:selected').val(),
                    work_state: $('#work_state option:selected').val(),
                    key_words: $('#key_words').val(),
                    work_p_start: $('#work_p_start').val(),
                    work_p_end: $('#work_p_end').val()
                }
              }
              tableIns.reload(options);
              layer.close(loading);
          });

          form.render();
          layer.close(loading);
    });

</script>

<script>
//时间控件
layui.use('laydate', function(){
  var laydate = layui.laydate;
  laydate.render({
    elem: '#work_p_end',
    type:'date',
    format:'yyyy-MM-dd',
    trigger: 'click'
  });
  laydate.render({
    elem: '#work_p_start',
    type:'date',
    format:'yyyy-MM-dd',
    trigger: 'click'
  });

});



</script>

{% endblock %}